function fig7_13

global lam

figure(1)
clf
% get(gcf)
set(gcf,'Position', [25 1028 560 309])
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)
subaxis(1,1,1,1,'MT',0.01,'MB',0.2,'MR',0.01,'ML',0.08,'P',0.04)

lam=20;

hold on
%axis equal
nx=100; ym=3;
ys=linspace(-ym,ym,nx);
for i=1:nx
    vs(i)=(ys(i)-ys(i)^3/3);
end
plot(ys,vs,'r','LineWidth',1.2)
axis([-2.3 2.3 -4/3 4/3])

tmax=2*pi;
y10=0.5; y20=0;
% y0=[y10 y20];
% options = odeset('RelTol', 1e-6,'AbsTol',1e-6);
% [t2,y2] = ode45(@rhs,[0 tmax],y0,options);
y0=[y10; y20];
tspan = [0 tmax];
options = rdpset('RelTol',1e-14,'AbsTol',1e-16);
[t2,y2] = radau(@Deriv,tspan,y0,options);

% determine limit cycle
% tmax=20*pi
% y0=[y10 y20];
% %  calculate solution using a MATLAB routine
% [tl,yl] = ode45(@rhs,[0 tmax],y0,options);

hold on

plot(y2(:,1),y2(:,2),'b','LineWidth',1.2)
plot(y2(1,1),y2(1,2),'.b','MarkerSize',20)

length(t2)

%say=['t = ', num2str(t0)];
text(-0.5,0.86,'B','FontSize',12,'Interpreter','latex')
text(-1.9,-0.15,'C','FontSize',12,'Interpreter','latex')
text(0.5,-0.86,'D','FontSize',12,'Interpreter','latex')
text(1.8,0.15,'A','FontSize',12,'Interpreter','latex')

% commands to label each axes
xticks([-2 -1 0 1 2])
%xticklabels({'-2/3','0','2/3'})
yticks([-2/3 0 2/3])
yticklabels({'$-2/3$','0','2/3'})
ax = gca;
ax.XAxis.TickLabelInterpreter = 'latex';
ax.YAxis.TickLabelInterpreter = 'latex';
set(gca,'FontSize',13)

xlabel('$y$\,-\,axis','Interpreter','latex','FontSize',14)
ylabel('$u$\,-\,axis','Interpreter','latex','FontSize',14)
grid on

box on

i=17;  ii=i+2;
arrowhead([y2(i,1) y2(ii,1)],[y2(i,2) y2(ii,2)],'b',[0.8 1.2],2);

i=657;  ii=i+2;
arrowhead([y2(i,1) y2(ii,1)],[y2(i,2) y2(ii,2)],'b',[0.8 1.2],2);

i=731;  ii=i+2;
arrowhead([y2(i,1) y2(ii,1)],[y2(i,2) y2(ii,2)],'b',[0.8 1.2],2);

hold off

%exportgraphics(gcf,'/Users/mark/Desktop/van1.pdf')


figure(2)
clf
% get(gcf)
set(gcf,'Position', [26 695 563 249])
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)
subaxis(1,1,1,1,'MT',0.01,'MB',0.2,'MR',0.01,'ML',0.05,'P',0.04)

hold on
plot(t2,y2(:,1),'b','LineWidth',1.2)
plot(0,y2(1,1),'.b','MarkerSize',20)
axis([0 6 -2.1 2.1])

set(gca,'ytick',[-2 -1 0 1 2])
set(gca,'YTickLabel',{'$-2$';'$-1$';'0';'1';'2'})

ax = gca;
ax.XAxis.TickLabelInterpreter = 'latex';
ax.YAxis.TickLabelInterpreter = 'latex';
set(gca,'FontSize',13)

xlabel('$\tau$\,-\,axis','Interpreter','latex','FontSize',14)
ylabel('$y$\,-\,axis','Interpreter','latex','FontSize',14)

grid on
text(4.1,0,'B','FontSize',12,'Interpreter','latex')
text(4.6,-1.8,'C','FontSize',12,'Interpreter','latex')
text(4.95,0,'D','FontSize',12,'Interpreter','latex')
text(3.7,1.8,'A','FontSize',12,'Interpreter','latex')

exportgraphics(gcf,'/Users/mark/Desktop/van2.pdf')

figure(3)
clf
% get(gcf)
set(gcf,'Position', [24 380 563 249])
co = [0 0 1;
    0 0.5 0;
    1 0 0;
    0 0.75 0.75;
    0.75 0 0.75;
    0.75 0.75 0;
    0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)
subaxis(1,1,1,1,'MT',0.01,'MB',0.2,'MR',0.01,'ML',0.05,'P',0.04)

hold on
plot(t2,y2(:,2),'b','LineWidth',1.5)
y2(1,2)
y2(2,2)
axis([0 6 -1 1])
xlabel('\tau-axis','FontWeight','bold')
ylabel('u-axis','FontWeight','bold')
grid on
set(gca,'FontSize',12)


%  define f(t,y)
%function dy=rhs(t,y)
function dy = Deriv(t, y)
global lam
dy=[lam^2*(y(1)*(1-y(1)^2/3)-y(2)); y(1)];
% dy=zeros(2,1);
% dy(1) = lam^2*(y(1)*(1-y(1)^2/3)-y(2));
% dy(2) = y(1);
% function z=dY(y,u)
% global lam
% z = lam^2*(y*(1-y^2/3)-u);
% 
% function z=dU(y,u)
% global lam
% z = y;






